﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using System.Data.SqlClient;
using System.Data;
using System.Collections;

using XJX.DBCore;

namespace XJX.DataLayer
{
    public sealed class Admin : XJX.DBCore.DBObject
    {
        public Admin(string newConnectionString) : base(newConnectionString) { }

        //
        public DataSet Ad_Search_Book_From_BID(string BID, string TableName, out int r)
        {
            SqlParameter[]
                parameters = { new SqlParameter("@BID", SqlDbType.VarChar, 12) };

            parameters[0].Value = BID;

            using (DataSet ds = RunProcedure("Ad_Search_Book_From_BID", parameters, TableName, out r))
            {
                return ds;
            }
        }

        //获得确认表，准备导出确认表。
        public DataSet Get_Admin_Confirm_Yes_List(string TableName)
        {
            SqlParameter[]
                parameters = { };

            using (DataSet ds = RunProcedure("Get_Admin_Confirm_Yes_List", parameters, TableName))
            {
                return ds;
            }
        }


        public int Confirm_One_Book_Arrived(string ID)
        {
            int r=0;
            int rowsAffected=0;

            SqlParameter[]
                parameters = { new SqlParameter("@id", SqlDbType.Int) };

            parameters[0].Value = ID;

            try
            {
                r = RunProcedure("Confirm_One_Book_Arrived", parameters, out rowsAffected);
            }
            catch (SqlException e)
            {
                throw new System.Exception(e.Message);
            }
            return r;
        }

        public int Ad_Clear_Confirm_Table_Info()
        {
            int r = 0;
            int rowsAffected = 0;

            SqlParameter[]
                parameters = { // 
                             };

            try
            {
                r = RunProcedure("Ad_Clear_Confirm_Table_Info", parameters, out rowsAffected);
            }
            catch (SqlException e)
            {
                throw new System.Exception(e.Message);
            }
            return r;
        }

        //验证管理员登录
        public int Ad_Verification_User_Log
            (
            string mobile,
            string pwd,
            out string ReturnFieldValue
            )
        {
            int rowsAffected;//受影响的行数．
            int ReturnValue;          //返回参数值

            SqlParameter[]
                parameters = {
								 new SqlParameter("@mobile",SqlDbType.VarChar,20), 
								 new SqlParameter("@pwd",SqlDbType.VarChar,50),
			};

            parameters[0].Value = mobile;
            parameters[1].Value = pwd;

            try
            {
                ReturnValue = RunProcedure("Ad_Verification_User_Log", parameters, out rowsAffected, out ReturnFieldValue);
            }
            catch (SqlException e)
            {
                throw new System.Exception(e.Message);
            }
            return ReturnValue;//返回0表示用户不存在，返回1表示正确登录。
        }

        //获取当前管理员信息
        public DataSet Ad_2_Get_Admin_Info(string schoolID)
        {

            SqlParameter[]
                parameters = {
								new SqlParameter("@schoolID",SqlDbType.VarChar,12)
							 };
            parameters[0].Value = schoolID;

            using (DataSet ds = RunProcedure("Ad_2_Get_Admin_Info", parameters, "AdminInfo"))
            {
                return ds;
            }
        }


    }
}
